Paging, Subsort Recordset

Paging, Subsort Recordset

am 02.08.2005 07:15:56 von Kevin

This is a multi-part message in MIME format.

------=_NextPart_000_0079_01C596E6.96A3AA40
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Can anyone point me to a code example where a recordset.absolutepage is =
sorted independantly of the original recordset. That is; if I populate =
an ADO recordset with an ORDER BY ListingDate clause, and I need to =
(subsort) recordset.absolutepage five of my paging on another field, say =
for example AskingPrice, I'm stuck.

My goal is for my users to be able to page through my recordset, sort a =
page if desired, and continue through the recordset. The records on any =
page are sorted, and the same records are displayed, just in a new =
(subsort) oder.=20

I'm not using the data controls, just plain ASP...

Thanks

Kev

Current code below...






<%
check_security(2)
%>
<%

If Session("UserID") =3D "" Then
Response.Redirect "Login.asp"
End if
=20
Dim rsItems, strSort
=20
strSort =3D request("sortby")
=20
strSQL =3D "SELECT Item.ItemID, Users.CompanyName, =
EquipmentTypes.EquipName, Item.EquipmentType, Item.LoadSize, =
Item.PickupDate, Item.SPCountry, Item.SPState, " & _
"Item.SPCity, Item.DPCountry, Item.DPState, Item.DPCity, =
Item.Description, Item.AskingPrice, Item.SellerID, Item.ListingDate, =
Item.ExpirationDate, Item.ItemStatus " & _
"FROM (Item INNER JOIN EquipmentTypes ON Item.EquipmentType =
=3D EquipmentTypes.EquipCode) LEFT JOIN Users ON Item.SellerID =3D =
Users.UserID " & _
"WHERE Item.ExpirationDate > #" & FormatDateTime(Now,2) & "# =
" & _
"AND ItemStatus =3D 'Active' "

If request("LoadSize") <> "" then
strSQL =3D strSQL & "AND LoadSize =3D '" & request("LoadSize") & "' =
"
End if
=20
If request("EquipmentType") <> "" then
strSQL =3D strSQL & "AND EquipmentType =3D '" & =
request("EquipmentType") & "' "
End if
=20
If request("SPCountry") <> "" then
strSQL =3D strSQL & "AND SPCountry =3D '" & request("SPCountry") & =
"' "
End if

If request("SPState") <> "" then
strSQL =3D strSQL & "AND SPState =3D '" & request("SPState") & "' "
End if

If request("DPCountry") <> "" then
strSQL =3D strSQL & "AND DPCountry =3D '" & request("DPCountry") & =
"' "
End if

If request("DPState") <> "" then
strSQL =3D strSQL & "AND DPState =3D '" & request("DPState") & "' "
End if

strSQL =3D strSQL & "ORDER BY PickupDate;"

page_no =3D request("page_no")
if page_no =3D "" then page_no =3D 1

Set rsItems =3D Server.CreateObject("ADODB.Recordset")
=20
if strSql <> "" then
rsItems.CursorLocation =3D 3
rsItems.CacheSize =3D 5
rsItems.Sort =3D "PickupDate, " & strSort
rsItems.Open strSql, objConn
if not rsItems.EOF then=20
rsItems.MoveFirst
rsItems.PageSize =3D 5
max_count =3D cInt(rsItems.PageCount)
num_recs =3D rsItems.RecordCount
rsItems.AbsolutePage =3D page_no
results =3D true
for each tmp in request.querystring
if tmp <> "page_no" AND tmp <> "sortby" then
request_string =3D request_string & tmp & "=3D" & =
request.querystring(tmp) & "&"
end if
next
else
results =3D false
rsItems.Close
end if
else
results =3D false
end if
rec_count =3D 0
%>














 

Browse Loads

  • Click Company Name to bid on the load.

  • Click the column headers to sort each Pickup Date by =
    the column name.

  • Place your mouse over the Type code to see the full =
    type description.

  • You cannot bid on your own loads.
  •  

    <%

    if results =3D true then

    %>










    <%

    do while not rsItems.EOF AND (rec_count < rsItems.Pagesize)

    on error resume next

    %>

    <% If Session("UserID") <> "" AND Session("UserID") <> =
    rsItems("SellerID") Then %>

    <% Else %>

    <% End If %>







    <%
    rsItems.MoveNext
    rec_count =3D rec_count + 1
    loop
    rsItems.Close
    Set rsItems =3D Nothing
    %>
    Company href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DLoadSize">Size
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DEquipmentType">Type
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DPickupDate">Pickup Date
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no %>&sortby=3DSPCity">Starting =
    Point
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DDPCity">Destination
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DAskingPrice">Payment Amt
    href=3D'Bid.asp?Item=3D<%=3DrsItems("ItemID")%>'><%=3DrsItems("ItemRefere=
    nce")%>
    align=3D'left'><%=3DrsItems("ItemReference")%> <%=3D =
    rsItems("LoadSize") %>
    title=3D'<%=3DrsItems("EquipName")%>'><%=3DrsItems("EquipmentType")%>=
    <%=3D =
    rsItems("PickupDate")%>
      href=3D"http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("SPCo=
    untry")%>&state=3D<%=3DrsItems("SPState")%>&city=3D<%=3DrsItems("SPCity")=
    %>&CID=3Dlfmaplink" target=3D"_blank"> size=3D"1">Map
     <%=3D rsItems("SPCity") & ", " & =
    rsItems("SPState")%>
      href=3D"http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("DPCo=
    untry")%>&state=3D<%=3DrsItems("DPState")%>&city=3D<%=3DrsItems("DPCity")=
    %>&CID=3Dlfmaplink" target=3D"_blank"> size=3D"1">Map
     <%=3D rsItems("DPCity") & ", " & =
    rsItems("DPState") %>
    <%=3D =
    formatcurrency(rsItems("AskingPrice")) %> 

    <% else %>

    No loads currently listed



    <%=20

    end if=20

    if max_count > 1 then=20

    %>
    class=3D"NavTable">







    <% if =
    page_no > 1 then %>
    =3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
    %>page_no=3D1&sortby=3D<% =3Drequest("sortby")%>">First

    <% else %>
    <% end if %>
    <% if =
    page_no > 1 then %>
    =3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
    %>page_no=3D<% =3Dpage_no-1 =
    %>&sortby=3D<%=3Drequest("sortby")%>">Previous

    <% else %>
    <% end if %>
    =
    Records: <%=3Dnum_recs%>
    <% if =
    cInt(page_no) < cInt(max_count) then %>
    =3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
    %>page_no=3D<% =3Dpage_no+1 %>&sortby=3D<% =
    =3Drequest("sortby")%>">Next

    <% end if %>
    <% if =
    cInt(page_no) < cInt(max_count) then %>
    =3Drequest.servervariables("script_name") %>?<% =3Drequest_string =
    %>page_no=3D<% =3DcInt(max_count) %>&sortby=3D<% =
    =3Drequest("sortby")%>">Last

    <% end if %>

    <% end if %>


    ------=_NextPart_000_0079_01C596E6.96A3AA40
    Content-Type: text/html;
    charset="Windows-1252"
    Content-Transfer-Encoding: quoted-printable



    charset=3Dwindows-1252">





    Can anyone point me to a code example =
    where a=20
    recordset.absolutepage is sorted independantly of the =
    original=20
    recordset.  That is; if I populate an ADO recordset with an ORDER =
    BY=20
    ListingDate clause, and I need to (subsort)=20
    recordset.absolutepage five of my paging on another =
    field, say=20
    for example AskingPrice, I'm stuck.

     

    My goal is for my users to be able to =
    page through=20
    my recordset, sort a page if desired, and continue through the=20
    recordset.  The records on any page are sorted, and the same =
    records are=20
    displayed, just in a new (subsort) oder. 

     

    I'm not using the data controls, just =
    plain=20
    ASP...

     

    Thanks

     

    Kev

     

    Current code below...

     

     

    <!--#include=20
    file=3D"Utilities.asp"-->
    <link href=3D"styles/main.css" =
    rel=3D"stylesheet"=20
    type=3D"text/css">
    <!--#include=20
    file=3D"header.asp"-->
    <!--#include=20
    file=3D"Menu.asp"-->
    <%
     =20
    check_security(2)
    %>
    <%

     

      If Session("UserID") =3D ""=20
    Then
        Response.Redirect "Login.asp"
      End=20
    if
     
      Dim rsItems, strSort
     
      strSort =
    =
    request("sortby")
     
      strSQL =3D "SELECT Item.ItemID,=20
    Users.CompanyName, EquipmentTypes.EquipName, Item.EquipmentType, =
    Item.LoadSize,=20
    Item.PickupDate, Item.SPCountry, Item.SPState, " &=20
    _
               =
    "Item.SPCity,=20
    Item.DPCountry, Item.DPState, Item.DPCity, Item.Description, =
    Item.AskingPrice,=20
    Item.SellerID, Item.ListingDate, Item.ExpirationDate, Item.ItemStatus " =
    &=20
    _
               "FROM =
    (Item=20
    INNER JOIN EquipmentTypes ON Item.EquipmentType =3D =
    EquipmentTypes.EquipCode) LEFT=20
    JOIN Users ON Item.SellerID =3D Users.UserID " &=20
    _
               "WHERE =

    Item.ExpirationDate > #" & FormatDateTime(Now,2) & "# " & =

    _
               "AND=20
    ItemStatus =3D 'Active' "

     

       If =
    request("LoadSize") <>=20
    "" then
         strSQL =3D strSQL & "AND =
    LoadSize =3D '"=20
    & request("LoadSize") & "' "
       End=20
    if
     
       If request("EquipmentType") <> =
    ""=20
    then
         strSQL =3D strSQL & "AND =
    EquipmentType =3D '"=20
    & request("EquipmentType") & "' "
       End=20
    if
       
       If request("SPCountry") =
    <>=20
    "" then
         strSQL =3D strSQL & "AND =
    SPCountry =3D '"=20
    & request("SPCountry") & "' "
       End =
    if

     

       If request("SPState") =
    <> ""=20
    then
         strSQL =3D strSQL & "AND SPState =
    =3D '" &=20
    request("SPState") & "' "
       End if

     

       If =
    request("DPCountry") <>=20
    "" then
         strSQL =3D strSQL & "AND =
    DPCountry =3D '"=20
    & request("DPCountry") & "' "
       End =
    if

     

       If request("DPState") =
    <> ""=20
    then
         strSQL =3D strSQL & "AND DPState =
    =3D '" &=20
    request("DPState") & "' "
       End if

     

         strSQL =3D =
    strSQL &=20
    "ORDER BY PickupDate;"

     

      page_no =3D =
    request("page_no")
      if=20
    page_no =3D "" then page_no =3D 1

     

      Set rsItems =
    Server.CreateObject("ADODB.Recordset")
      
     if =
    strSql=20
    <> "" then
     rsItems.CursorLocation =3D =
    3
     rsItems.CacheSize=20
    =3D 5
     rsItems.Sort =3D "PickupDate, " & =
    strSort
     rsItems.Open=20
    strSql, objConn
      if not rsItems.EOF then=20

       rsItems.MoveFirst
       rsItems.Page=
    Size =
    5
       max_count =
    cInt(rsItems.PageCount)
       num_recs =
    rsItems.RecordCount
       rsItems.AbsolutePage =
    page_no
       results =3D true
       for =
    each tmp in=20
    request.querystring
        if tmp <> "page_no" =
    AND tmp=20
    <> "sortby" then
        request_string =
    request_string & tmp & "=3D" & request.querystring(tmp) =
    &=20
    "&"
        end=20
    if
       next
     else
      results =
    false
      rsItems.Close
     end =
    if
    else
     results =
    false
    end if
    rec_count =
    0
    %>
            <table=20
    cellpadding=3D"0"=20
    cellspacing=3D"0">
            =
     =20
    <tr>
              =
    ; =20
    <td>&nbsp;</td>
          &n=
    bsp;  =20
    </tr>
             =20
    <tr>
              =
    ; =20
    <td><h1>Browse=20
    Loads</h1></td>
           =
      =20
    </tr>
             =20
    <tr>
              =
    ; =20
    <td><li>Click Company Name to bid on the=20
    load.</li>
             =
    ;    =20
    <li>Click the column headers to sort each Pickup Date by the =
    column=20
    name.</li>
             =
    ;    =20
    <li>Place your mouse over the Type code to see the full type=20
    description.</li>
           &nbs=
    p;     =20
    <li>You cannot bid on your own=20
    loads.</li></td>
           =
    ;  =20
    </tr>
             =20
    <tr>
              =
    ; =20
    <td>&nbsp;</td>
          &n=
    bsp;  =20
    </tr>
           =20
    </table>
    <%

     

    if results =3D true then

     

    size=3D2>%>
           =20
    <table width=3D"760px" cellpadding=3D'0'=20
    cellspacing=3D'0'>
            =
     =20
    <tr>
              =
    ; =20
    <td=20
    class=3D'tdHeader'>Company</td>
         =
    ;      =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no=20
    %>&sortby=3DLoadSize">Size</a></td>
      =
             =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no=20
    %>&sortby=3DEquipmentType">Type</a></td>
     &=
    nbsp;         =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no %>&sortby=3DPickupDate">Pickup =

    Date</a></td>
           &n=
    bsp;   =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no %>&sortby=3DSPCity">Starting=20
    Point</a></td>
           &=
    nbsp;   =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no=20
    %>&sortby=3DDPCity">Destination</a></td>
     &=
    nbsp;         =20
    <td class=3D'tdHeader'><a=20
    href=3D"<%=3Drequest.servervariables("script_name")%>?<% =
    =3Drequest_string=20
    %>page_no=3D<% =3Dpage_no =
    %>&sortby=3DAskingPrice">Payment=20
    Amt</a></td>
           &nb=
    sp; =20
    </tr>
             =20
    <%

     

    do while not rsItems.EOF AND (rec_count =
    <=20
    rsItems.Pagesize)

     

    on error resume next

     

    size=3D2>%>
              =

    <tr>
              =
    ; =20
    <% If Session("UserID") <> "" AND Session("UserID") <>=20
    rsItems("SellerID") Then=20
    %>
              &nbs=
    p;=20
    <td align=3D"left" class=3D'tdData'><a=20
    href=3D'Bid.asp?Item=3D<%=3DrsItems("ItemID")%>'><%=3DrsItems=
    ("ItemReference")%></a></td>
        &n=
    bsp;      =20
    <% Else=20
    %>
              &nbs=
    p;=20
    <td class=3D'tdData'=20
    align=3D'left'><%=3DrsItems("ItemReference")%></td>
    &nb=
    sp;          =20
    <% End If=20
    %>
              &nbs=
    p;=20
    <td class=3D'tdData' align=3D'center'><%=3D rsItems("LoadSize") =

    %></td>
             =
    ;  =20
    <td class=3D'tdData' align=3D'center'><a=20
    title=3D'<%=3DrsItems("EquipName")%>'><%=3DrsItems("Equipment=
    Type")%></a></td>
          &=
    nbsp;    =20
    <td align=3D'center' class=3D'tdData'><%=
    rsItems("PickupDate")%></td>
         &n=
    bsp;     =20
    <td align=3D'left' nowrap class=3D'tdData'>&nbsp;<a =
    href=3D" href=3D'http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("SPCo=
    untry")%>&state=3D<%=3DrsItems("SPState")%>&city=3D<%=3DrsItems("=
    SPCity")%>&CID=3Dlfmaplink'>http://www.mapquest.com/maps /map.adp?coun=
    try=3D<%=3DrsItems("SPCountry")%>&state=3D<%=3DrsItems("SPSt=
    ate")%>&city=3D<%=3DrsItems("SPCity")%>&CID=3Dlfmaplink<=
    /A>"=20
    target=3D"_blank"><font color=3D"#FF0000"=20
    size=3D"1">Map</font></a>&nbsp;<%=3D =
    rsItems("SPCity") &=20
    ", " &=20
    rsItems("SPState")%></td>
          =
    ;     =20
    <td align=3D'left' nowrap class=3D'tdData'>&nbsp;<a =
    href=3D" href=3D'http://www.mapquest.com/maps/map.adp?country=3D<%=3DrsItems("DPCo=
    untry")%>&state=3D<%=3DrsItems("DPState")%>&city=3D<%=3DrsItems("=
    DPCity")%>&CID=3Dlfmaplink'>http://www.mapquest.com/maps /map.adp?coun=
    try=3D<%=3DrsItems("DPCountry")%>&state=3D<%=3DrsItems("DPSt=
    ate")%>&city=3D<%=3DrsItems("DPCity")%>&CID=3Dlfmaplink<=
    /A>"=20
    target=3D"_blank"><font color=3D"#FF0000"=20
    size=3D"1">Map</font></a>&nbsp;<%=3D =
    rsItems("DPCity") &=20
    ", " & rsItems("DPState")=20
    %></td>
             =
    ;  =20
    <td class=3D'tdData' align=3D'right'><%=
    formatcurrency(rsItems("AskingPrice"))=20
    %>&nbsp;</td>
           &=
    nbsp; =20
    </tr>
             =20
    <%
    rsItems.MoveNext
    rec_count =3D rec_count +=20
    1
    loop
    rsItems.Close
    Set rsItems =
    Nothing
    %>
           =20
    </table>
            <% else=20
    %>
           =20
    <center>
              =

    <h2>No loads currently=20
    listed</h2>
           =20
    </center>
            <%=20

     

    end if

     

    if max_count > 1 then

     

    size=3D2>%>
           =20
    <table width=3D"760px" cellpadding=3D"0" cellspacing=3D"0"=20
    class=3D"NavTable">
            =
    ; =20
    <tr>
              =
    ; =20
    <td align=3Dcenter width=3D"20%" class=3DNavFont><% if page_no =
    > 1 then=20
    %>
              &nbs=
    p;  =20
    <a class=3DHeaderFont href=3D"<% =
    =3Drequest.servervariables("script_name")=20
    %>?<% =3Drequest_string %>page_no=3D1&sortby=3D<%=20
    =3Drequest("sortby")%>">First</a>
        =
             =20
    <% else=20
    %>
              &nbs=
    p;  =20
    <% end if=20
    %>
              &nbs=
    p;=20
    </td>
             &nbs=
    p; =20
    <td align=3Dcenter width=3D"20%" class=3DNavFont><% if page_no =
    > 1 then=20
    %>
              &nbs=
    p;  =20
    <a class=3DHeaderFont href=3D"<% =
    =3Drequest.servervariables("script_name")=20
    %>?<% =3Drequest_string %>page_no=3D<% =3Dpage_no-1=20
    %>&sortby=3D<%=3Drequest("sortby")%>">Previous</a><=
    BR>           &nbs=
    p; =20
    <% else=20
    %>
              &nbs=
    p;  =20
    <% end if=20
    %>
              &nbs=
    p;=20
    </td>
             &nbs=
    p; =20
    <td align=3Dcenter width=3D"20%" class=3DNavFont>=20
    Records:&nbsp;<%=3Dnum_recs%>=20
    </td>
             &nbs=
    p; =20
    <td align=3Dcenter width=3D"20%" class=3DNavFont><% if =
    cInt(page_no) <=20
    cInt(max_count) then=20
    %>
              &nbs=
    p;  =20
    <a class=3DHeaderFont href=3D"<% =
    =3Drequest.servervariables("script_name")=20
    %>?<% =3Drequest_string %>page_no=3D<% =3Dpage_no+1 =
    %>&sortby=3D<%=20
    =3Drequest("sortby")%>">Next</a>
        &=
    nbsp;        =20
    <% end if=20
    %>
              &nbs=
    p;=20
    </td>
             &nbs=
    p; =20
    <td align=3Dcenter width=3D"20%" class=3DNavFont><% if =
    cInt(page_no) <=20
    cInt(max_count) then=20
    %>
              &nbs=
    p;  =20
    <a class=3DHeaderFont href=3D"<% =
    =3Drequest.servervariables("script_name")=20
    %>?<% =3Drequest_string %>page_no=3D<% =3DcInt(max_count)=20
    %>&sortby=3D<%=20
    =3Drequest("sortby")%>">Last</a>
        &=
    nbsp;        =20
    <% end if=20
    %>
              &nbs=
    p;=20
    </td>
             =20
    </tr>
           =20
    </table>
    <% end if %>
    <!--#include=20
    file=3D"footer.asp"-->


    ------=_NextPart_000_0079_01C596E6.96A3AA40--

    Re: Paging, Subsort Recordset

    am 02.08.2005 15:36:21 von reb01501

    "Kevin" wrote in message
    news:ey6nEFylFHA.664@TK2MSFTNGP10.phx.gbl...
    > Can anyone point me to a code example where a recordset.absolutepage
    > is sorted independantly of the original recordset. That is; if I populate
    an
    > ADO recordset with an ORDER BY ListingDate clause, and I need to
    > (subsort) recordset.absolutepage five of my paging on another field, say
    > for example AskingPrice, I'm stuck.

    You will need to create a new recordset containing just the records from
    page 5. There are two ways to do this. Which one you pick depends on how
    many records are in the recordset.

    a) Use the recordset's Clone method to create a clone of your recordset
    (hopefully, you've previously disconnected the recordset and closed the
    connection). Then use a loop to delete all the records from the clone, move
    to page 5 in the original recordset, use a loop to write the records from
    page 5 into the clone (using AddNew), and modify the Sort property of the
    clone.

    b) Create an ad hoc recordset using a loop to add the fields from the
    original recordset to the Fields collection of the new recordset. Then use
    AddNew as above to add the page 5 records to the new recordset.

    Here is method a - this is untested air-code so it may contain typos or
    syntax errors:

    ....
    rsItems.Open strSql, objConn
    set rsItems.ActiveConnection=Nothing
    objConn.close: set objConn=nothing
    set rsReSort=rsItems.Clone
    do until rsResort.eof
    rsResort.Delete
    rsResort.MoveNext
    loop
    rsItems.AbsolutePage=5
    do until rsItems.eof OR _
    rsResort.RecordCount = rsItems.PageSize
    rsResort.AddNew
    for each fld in rsItems.Fields
    rsResort(fld.Name)=fld.Value
    next
    rsResort.Update
    rsItems.MoveNext
    loop
    rsResort.Sort = "..."

    HTH,
    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From header is
    my spam trap, so I don't check it very often. You will get a quicker
    response by posting to the newsgroup.